|
|
|
|
|
|
|
Figure 7.2
Use titles and icons to give the user
visual cues to the nature of the message |
|
|
|
|
|
|
|
|
Returning a Value from the MsgBox Function |
|
|
|
|
|
|
|
|
The MsgBox function, as described previously, works fine for informing users of a problem or prompting them to take an action. However, to get a decision from the users, you need to use the MsgBox function's return value. There are two key differences to using the MsgBox function this wayyou must deal with the function's return value, possibly by assigning it to a variable, and you must enclose the arguments of the function in parentheses. This value reports which command button a user clicked. The following line of code shows how the value returned by the function can be assigned to a variable for further processing: |
|
|
|
|
|
|
|
|
nResult = MsgBox("The printer is not responding", _
vbRetryCancel,"Printer Error!") |
|
|
|
|
|
|
|
|
Additional statements after the preceding code could check the value of the variable nResult with, for example, an If statement and take appropriate action. |
|
|
|
|
|
|
|
|
Choosing among the Command Button Sets |
|
|
|
|
|
|
|
|
The following six sets of command buttons can be used in the MsgBox function: |
|
|
|
|
|
|
|
|
OK. Displays a single button with the caption OK. This button simply directs the user to acknowledge receipt of the message before continuing. |
|
|
|
|
|
|
|
|
OK, Cancel. Displays two buttons in the message box, letting the user choose between accepting the message and requesting a cancellation of the operation. |
|
|
|
|
|
|
|
|
Abort, Retry, Ignore. Displays three buttons, usually along with an error message. The user can choose to abort the operation, retry it, or ignore the error and attempt to continue with program execution. |
|
|
|
|
|
|
|
|
Yes, No, Cancel. Displays three buttons, typically with a question. The user can answer yes or no to the question, or choose to cancel the operation. |
|
|
|
|
|
|
|
|
Yes, No. Displays two buttons for a simple yes or no choice. |
|
|
|
|
|
|
|
|
Retry, Cancel. Displays the two buttons that allow the user to retry the operation or cancel it. A typical use is reporting that the printer is not responding. The user can either retry after fixing the printer or cancel the printout. |
|
|
|
|
|
|
|
|
To specify the command buttons you want to appear in the message box, you need to specify a value for the buttons argument of the MsgBox function. The values for each of the command button sets are listed in Table 7.2. |
|
|
|
|
|